set printback=OFF.

TITLE LIS Cross-section Data center in Luxembourg.

TITLE email: usersupport@lisdatacenter.org .

TITLE LIS Self Teaching Package 2022.

TITLE Part I: Inequality, poverty, and social policy.
TITLE SPSS version.

TITLE last change of this version of the syntax: 15-01-2022.

TITLE Exercise 6: Comparing income concepts.

set printback=OFF. 
 
define dataprepare ().  
SET ERRORS OFF.      
compute miss_comp = 0.   
if (missing(dhi) or missing(hifactor) or missing(hi33) or missing(hpub_i) or missing(hpub_u) or missing(hpub_a) or missing(hiprivate) or missing(hxitsc)) miss_comp = 1.   
select if miss_comp eq 0.   
* create person weight as hwgt times number of household members.    
compute wt = hwgt*nhhmem .    
compute mi_tb = hifactor + hi33 + hiprivate.   
compute siti_tb = hifactor +hi33 +  hiprivate + hpub_i + hpub_u - hxitsc.   
compute sa_tb = hifactor + hi33 + hiprivate + hpub_a.   
!enddefine .    
   
define prepare ().     
SET ERRORS OFF.    
* select only records if dhi filled.    
select if not missing(inc_var) .    
* recode negaive dhi into zero   
if (inc_var <0) inc_var =0.   
EXECUTE.    
compute inc_var_log = ln(inc_var).    
EXECUTE.    
if (missing(inc_var_log) & NOT(missing(inc_var))) inc_var_log =0.    
EXECUTE.    
weight by wt.    
!enddefine .    
   
define decilecalc ().    
*** decile procedure.     
preserve .     
set tvars names tnumbers values.     
dataset declare decileratio.     
WEIGHT BY hwgt.    
sort cases by did.     
split file by did.     
OMS         
 / select tables         
 / if command = ['Frequencies'] subtypes=['Statistics']         
 /destination format = sav        outfile = 'decileratio'         
 /columns sequence = [l1 r2] .     
frequencies variables = inc_var_log   
  /percentiles = 25 50 75    
  /format = notable .    
OMSEND.    
weights off.    
restore.    
match files file = *    
  /table = 'decileratio'    
  /rename (var1 = did)    
  /by did .   
DATASET CLOSE decileratio.   
!enddefine .     
    
define topbottom ().    
weight by wt.    
COMPUTE iqr= inc_var_log_75- inc_var_log_25.    
EXECUTE.    
* detect upper bound for extreme values    
COMPUTE upper_bound= inc_var_log_75+ (iqr * 3).    
EXECUTE.    
COMPUTE lower_bound= inc_var_log_25- (iqr * 3).    
EXECUTE.    
* top code income at upper bound for extreme values    
if inc_var >exp(upper_bound) inc_var =exp(upper_bound).     
EXECUTE.    
* bottom code income at lower bound for extreme values    
if inc_var <exp(lower_bound) inc_var =exp(lower_bound).    
EXECUTE.    
* create equivalised income, set equivalence scale as square root of household members    
compute ey = inc_var /(nhhmem**0.5).     
!enddefine .     

define povcalc ().  
aggregate outfile = *   
   mode = addvariables   
   / break = did   
   / ey_median = median(ey)  .    
compute povline5 = ey_median * 0.5 .  
match files file=*/keep  
did povline5.  
Dataset copy poverty.  
!enddefine .   

define povcalccnt ().  
MATCH FILES /FILE=*   
  /FILE='poverty'   
  /RENAME (did = d0)   
  /DROP= d0.   
EXECUTE.  
compute poor50 = 0 .  
if ey lt povline5 poor50 = 100 .  
variable labels poor50 'overall poverty rate 50%'.  
weight by wt.
descriptives  poor50 /statistics=mean /format=notable. 
!enddefine .  
  
define ginicalc ()    
sort cases by ey (a).     
compute cumwgt = cumwgt + wt.     
leave cumwgt.     
aggregate outfile= *    
   mode = addvariables    
    /break= did    
    /meany= mean(ey)    
    /meanr= mean (cumwgt)    
    /n=n.    
compute devy= ey - meany.     
compute rank= cumwgt/n.     
compute devr = (rank - 0.5).     
compute prod= devy*devr.     
aggregate outfile= *    
    /break=did    
    /sumprod= sum(prod)    
    /meany= mean(ey)    
    /n=n.    
compute cov= sumprod/(n-1).    
compute gini=cov*2/meany.    
formats gini (f10.4).    
descriptives var=gini .  
!enddefine .  
  
get file = gt06h /keep=did dhi hifactor hi33 hpublic hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt nhhmem nhhmem17 nhhmem65  .   
dataprepare.  
* set one input parameter (income variable).    
compute inc_var =dhi.   
prepare.   
decilecalc.   
topbottom.     
povcalc.  
compute poor50 = 0 .  
if ey lt povline5 poor50 = 100 .  
variable labels poor50 'overall poverty rate 50%'.  
weight by wt.
descriptives  poor50 /statistics=mean /format=notable.  
TITLE Gini using dhi.  
ginicalc.    
   
get file = gt06h /keep=did dhi hifactor hi33 hpublic hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt nhhmem nhhmem17 nhhmem65 .   
dataprepare.   
* set one input parameter (income variable).   
compute inc_var = mi_tb.   
prepare.   
decilecalc.   
topbottom. 
TITLE Poverty using mi_tb.     
povcalccnt.
TITLE Gini using mi_tb.
ginicalc.  

get file = gt06h /keep=did dhi hifactor hi33 hpublic hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt nhhmem nhhmem17 nhhmem65 . 
dataprepare. 
* set one input parameter (income variable).   
compute inc_var = siti_tb. 
prepare.   
decilecalc.   
topbottom.   
TITLE Gini using siti_tb.  
povcalccnt.
TITLE Gini using siti_tb.  
ginicalc.  

get file = gt06h /keep=did dhi hifactor hi33 hpublic hpub_i hpub_u hpub_a hiprivate hxitsc hpopwgt nhhmem grossnet hwgt nhhmem nhhmem17 nhhmem65 . 
dataprepare. 
* set one input parameter (income variable).   
compute inc_var = sa_tb. 
prepare.   
decilecalc.   
topbottom. 
TITLE Poverty using sa_tb. 
povcalccnt.    
TITLE Gini using sa_tb.
ginicalc.  
